home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 8605 / 8605.xpi / chrome / content / main.js < prev    next >
Encoding:
Text File  |  2009-07-18  |  23.0 KB  |  634 lines

  1. function deviantAnywhere()
  2. {
  3.     this.messagesURL = "http://my.deviantart.com/messages/";
  4.     this.loginURL    = "https://www.deviantart.com/users/login";
  5.  
  6.  
  7.     this.REGEXP_DEVIATIONS = /<a href=".*?">(\d+) (?:Deviation|Deviations)<\/a>/;
  8.     //<a href=".*?">(\d+) (?:Deviation|Deviations)</a>
  9.     this.REGEXP_MESSAGES = /<a href="http:\/\/my\.deviantart\.com\/messages\/"(?: title="(.*?)")?>(.*?)<\/a>/;
  10.     //<a href="http://my\.deviantart\.com/messages/"(?: title="(.*?)")?>(.*?)</a>
  11.     this.REGEXP_NOTES = /<a href=".*?">(\d+) (?:Note|Notes)<\/a>/;
  12.     //<a href=".*?">(\d+) (?:Note|Notes)</a>
  13.     this.REGEXP_CONTESTS = /\["oq:contests.*?"count":(\d)+/;
  14.     //\["oq:contests.*?"count":(\d)+
  15.     this.REGEXP_ADMIN = /\["oq:admin.*?"count":(\d+)/;
  16.     //\["oq:admin.*?"count":(\d+)
  17.     this.REGEXP_SPLIT_MSG = /(\d+)(\w{1,2})/
  18.     //(\d+)(\w{1,2})
  19.     this.REGEXP_DEVIANTNAME = /<div class="text loggedin">(?:<span>Deviant <\/span>)| .*?<span class="loggedin a">(.)<a class="u" href=".*?">(.*?)<\/a>/
  20.     //<div class="text loggedin">(?:<span>Deviant </span>)| .*?<span class="loggedin a">(.)<a class="u" href=".*?">(.*?)</a>
  21.     this.REGEXP_CRITIQUES = /\["oq:devwatch:\d*?:\d*?:f:tg=critiques"\].*?"count":(\d*)/
  22.     //\["oq:devwatch:\d*?:\d*?:f:tg=critiques"\].*?"count":(\d*)
  23.  
  24.     this.REGEXP_PREV_DEVIATIONS = /"display_class":\["deviation".*?"username":".*?","who":"(.)<a class=\\"u\\" href=\\"(.*?)">(.*?)<\\\/a>",.*?"title":"<a href=\\"(.*?)">(.*?)<\\\/a>",/
  25.     //"display_class":\["deviation".*?"username":".*?","who":"(.)<a class=\\"u\\" href=\\"(.*?)">(.*?)<\\/a>",.*?"title":"<a href=\\"(.*?)">(.*?)<\\/a>",
  26.     this.REGEXP_PREV_NOTES = /"app":"unread notes","who":"(.)<a class=\\"u\\" href=\\"(.*?)">(.*?)<\\\/a>".*?"title":"<a href=\\"(.*?)">(.*?)<\\\/a>"/
  27.     //"app":"unread notes","who":"(.)<a class=\\"u\\" href=\\"(.*?)">(.*?)<\\/a>".*?"title":"<a href=\\"(.*?)">(.*?)<\\/a>"
  28.     this.REGEXP_PREV_FAVS = /\["collect","activity","line"\],"who":"(.)<a class=\\"u\\" href=\\"(.*?)\">(.*?)<\\\/a>.*?"collection":"<a href=\\"(.*?)\">(.*?)<\\\/a>.*?"title":"<a href=\\"(.*?)\\">(.*?)<\\\/a>/
  29.     //\["collect","activity","line"\],"who":"(.)<a class=\\"u\\" href=\\"(.*?)\">(.*?)<\\/a>.*?"collection":"<a href=\\"(.*?)\">(.*?)<\\/a>.*?"title":"<a href=\\"(.*?)\\">(.*?)<\\/a>
  30.     this.REGEXP_PREV_WATCH = /\["watched","activity","line"\],"who":"(.)<a class=\\"u\\" href=\\"(.*?)\\">(.*?)<\\\/a>/
  31.     //\["watched","activity","line"\],"who":"(.)<a class=\\"u\\" href=\\"(.*?)\\">(.*?)<\\/a>
  32.     this.REGEXP_PREV_COMMENTS = /\["comment","text"\].*?"who":"(.)<a class=\\"u\\" href=\\"(.*?)\\">(.*?)<\\\/a>.*?"title":".??<a.*?href=\\"(.*?)\\">(.*?)<\\\/a>.*?"url":"(.*?)"/
  33.     //\["comment","text"\].*?"who":"(.)<a class=\\"u\\" href=\\"(.*?)\\">(.*?)<\\/a>.*?"title":".??<a.*?href=\\"(.*?)\\">(.*?)<\\/a>.*?"url":"(.*?)"
  34.     this.REGEXP_PREV_CRITIQUES = /"app":"deviantWATCH","ts":"\d*?","display_class":\["critique","text"\],"line":"(.)<a .*?href=\\"(.*?)\\\/\\">(.*?)<\\\/a> posted a <a.*?href=\\"(.*?)\">critique<\\\/a> of <i class=\\"icon i2\\"><\\\/i> <a.*?href=\\"(.*?)\\">(.*?)<\\\/a> by (.)<a.*?href=\\"(.*?)\\\/\\">(.*?)<\\\/a>/
  35.     //"app":"deviantWATCH","ts":"\d*?","display_class":\["critique","text"\],"line":"(.)<a .*?href=\\"(.*?)\\/\\">(.*?)<\\/a> posted a <a.*?href=\\"(.*?)\">critique<\\/a> of <i class=\\"icon i2\\"><\\/i> <a.*?href=\\"(.*?)\\">(.*?)<\\/a> by (.)<a.*?href=\\"(.*?)\\/\\">(.*?)<\\/a>
  36.     this.REGEXP_PREV_JOURNALS = /"app":"deviantWATCH","display_class":\["journal","text"\].*?"username":".*?","who":"(.)<a class=\\"u\\" href=\\"(.*?)">(.*?)<\\\/a>",.*?"title":"<a href=\\"(.*?)">(.*?)<\\\/a>",/
  37.     //"app":"deviantWATCH","display_class":\["journal","text"\].*?"username":".*?","who":"(.)<a class=\\"u\\" href=\\"(.*?)">(.*?)<\\/a>",.*?"title":"<a href=\\"(.*?)">(.*?)<\\/a>",
  38.         
  39.     this.descs = new Array();
  40.  
  41.     this.descs['N'] = "Notice::Notices";
  42.     this.descs['A'] = "Activity Message::Activity Messages";
  43.     this.descs['R'] = "Reply::Replies";
  44.     this.descs['UN'] = "Unread Note::Unread Notes";
  45.     this.descs['J'] = 'Journal::Journals';
  46.     this.descs['C'] = 'Comment::Comments';
  47.     this.descs['D'] = 'Deviation::Deviations';
  48.     this.descs['P'] = 'Poll::Polls';
  49.     this.descs['CA'] = 'Contest Announcement::Contest Announcements';
  50.     this.descs['NW'] = 'News Article::News Articles';
  51.     this.descs['AM'] = 'Admin Message::Admin Messages';
  52.     this.descs['WC'] = 'Watched Critique::Watched Critiques';
  53.  
  54.  
  55.     this.messages = new Array();
  56.     this.req = new XMLHttpRequest();
  57.     this.loginReq = new XMLHttpRequest();
  58.  
  59.     this.loginRetry = 0;
  60.     this.timer = null;
  61.  
  62.     this.status = {};
  63.  
  64.     this.status.message = "Started...";
  65.     this.status.error = false;
  66.  
  67.     this.panel = null;
  68.  
  69.     this.loadAnimText = new Array();
  70.     this.loadAnimText[0] = "Loading";
  71.     this.loadAnimText[1] = "Loading.";
  72.     this.loadAnimText[2] = "Loading..";
  73.     this.loadAnimText[3] = "Loading...";
  74.  
  75.     this.loadAnimStep = 0;
  76.     this.didLoad = false;
  77.     this.loadAnimTimer = null;
  78.  
  79.     this.alertUrl = null;
  80.     this.firstTime = true;
  81.  
  82.     this.prev_deviations = new Array();
  83.     //0 - deviantName
  84.     //1 - deviant link
  85.     //2 - deviation name
  86.     //3 - deviation link
  87.  
  88.     
  89.     this.prev_notes = new Array();
  90.     //0 - deviant name
  91.     //1 - deviant link
  92.     //2 - item name
  93.     //3 - item link
  94.  
  95.     this.prev_watch = new Array();
  96.     //0 - deviant name
  97.     //1 - deviant link
  98.  
  99.     this.prev_comments = new Array();
  100.     //0 - deviant name
  101.     //1 - deviant link
  102.     //2 - deviation name
  103.     //3 - deviation link
  104.     //4 - comment link
  105.  
  106.     this.prev_favs = new Array();
  107.     //0 - deviant name
  108.     //1 - deviant link
  109.     //2 - deviation name
  110.     //3 - deviation link
  111.     //4 - collection name
  112.     //5 - collection link
  113.  
  114.     this.prev_critiques = new Array();
  115.     //0 - critiquer name
  116.     //1 - critiquer link
  117.     //2 - critique link
  118.     //3 - critiqued art link
  119.     //4 - critiqued art name
  120.     //5 - artist name
  121.     //6 - artist link
  122.  
  123.     this.prev_journals = new Array();
  124.     //0 - deviantName
  125.     //1 - deviant link
  126.     //2 - journal name
  127.     //3 - journal link
  128. }
  129.  
  130. deviantAnywhere.prototype =
  131. {
  132.     init: function()
  133.     {
  134.         panel = document.getElementById("dAPanel");
  135.         this.loadAnim();
  136.         lastMessages = ro_cvds_daUtils.getPref("lastMessages");
  137.         this.messages = ro_cvds_daUtils.JSON2array(lastMessages);
  138.  
  139.         if (ro_cvds_daUtils.getPref("customLook",ro_cvds_daUtils.boolPref))
  140.         {
  141.             if (ro_cvds_daUtils.getPref("showIcon",ro_cvds_daUtils.boolPref))
  142.                 panel.setAttribute("showIcon","true");
  143.             panel.setAttribute("class","customLook");
  144.             panel.style.backgroundColor = ro_cvds_daUtils.getPref("bkgcolor",ro_cvds_daUtils.stringPref);
  145.             panel.style.borderColor = ro_cvds_daUtils.getPref("bkgcolor",ro_cvds_daUtils.stringPref);
  146.             panel.style.color = ro_cvds_daUtils.getPref("textcolor",ro_cvds_daUtils.stringPref);
  147.         }
  148.  
  149.         this.retrieveMessages();
  150.     },
  151.  
  152.  
  153.     loadAnim: function()
  154.     {
  155.         panel.setAttribute("label",this.loadAnimText[this.loadAnimStep]);
  156.         if (this.loadAnimStep<this.loadAnimText.length-1)
  157.             this.loadAnimStep++;
  158.         else
  159.             this.loadAnimStep = 0;
  160.         if (!this.didLoad)
  161.             loadAnimTimer = setTimeout("ro_cvds_daInstance.loadAnim()",500);
  162.     },
  163.  
  164.     killAnimation: function()
  165.     {
  166.         didLoad = true;
  167.         clearTimeout(loadAnimTimer);
  168.     },
  169.  
  170.     retrieveMessages: function()
  171.     {
  172.         if (ro_cvds_daUtils.getPref("autoupdate",ro_cvds_daUtils.boolPref) || this.firstTime)
  173.         {
  174.             this.changeStatus("Retrieve messages in progress...");
  175.             this.firstTime = false;
  176.             this.req.open('GET', this.messagesURL, true);
  177.             this.req.channel.loadFlags |= Components.interfaces.nsIRequest.LOAD_BYPASS_CACHE;
  178.             this.req.onreadystatechange = this.parseResponse;
  179.             this.req.setRequestHeader("Pragma", "no-cache");
  180.             this.req.setRequestHeader("Cache-Control", "no-cache");
  181.             this.req.send(null);
  182.         }
  183.         this.timer = setTimeout("ro_cvds_daInstance.retrieveMessages()",ro_cvds_daUtils.getPref("checktime",ro_cvds_daUtils.intPref)*1000);
  184.     },
  185.  
  186.     changeStatus: function(message,wasError)
  187.     {
  188.         this.status.message = message;
  189.         this.status.error = wasError;
  190.  
  191.         if (this.status.error)
  192.             panel.setAttribute("mode","error");
  193.         else
  194.             panel.setAttribute("mode","active");
  195.     },
  196.  
  197.     parseResponse: function()
  198.     {
  199.         if (ro_cvds_daInstance.req.readyState == 4)
  200.         {
  201.             if(ro_cvds_daInstance.req.status == 200)
  202.             {
  203.                 ro_cvds_daInstance.killAnimation();
  204.  
  205.                 html = this.responseText;
  206.  
  207.                 //mesages
  208.                 labelText = ""
  209.                 overalText = ""
  210.                 match = ro_cvds_daInstance.REGEXP_MESSAGES.exec(html);
  211.                 if (match!=null)
  212.                 {
  213.                     labelText = match[1];
  214.                     overalText = match[2];
  215.                 }
  216.  
  217.                 //deviations
  218.                 deviations = null;
  219.                 match = ro_cvds_daInstance.REGEXP_DEVIATIONS.exec(html);
  220.                 if (match != null && match.length > 1)
  221.                     deviations = match[1];
  222.  
  223.                 //notes
  224.                 notes = null;
  225.                 match = ro_cvds_daInstance.REGEXP_NOTES.exec(html);
  226.                 if (match != null && match.length > 1)
  227.                     notes = match[1];
  228.  
  229.                 //contests
  230.                 contests = null;
  231.                 match = ro_cvds_daInstance.REGEXP_CONTESTS.exec(html);
  232.                 if (match != null && match.length > 1)
  233.                     contests = match[1];
  234.  
  235.                 //admin
  236.                 admin = null;
  237.                 match = ro_cvds_daInstance.REGEXP_ADMIN.exec(html);
  238.                 if (match != null && match.length > 1)
  239.                     admin = match[1];
  240.  
  241.                 //critiques
  242.                 critiques = null;
  243.                 match = ro_cvds_daInstance.REGEXP_CRITIQUES.exec(html);
  244.                 if (match != null && match.length > 1)
  245.                     critiques = match[1];
  246.  
  247.  
  248.                 if (overalText!=" No Messages")
  249.                 {
  250.                     _messages = new Array();
  251.                     if (labelText != "")
  252.                         _messages = labelText.split(", ");
  253.  
  254.                     match = ro_cvds_daInstance.REGEXP_DEVIANTNAME.exec(html);
  255.                     deviantName = match[1]+match[2];
  256.  
  257.                     newMessages = new Array();
  258.  
  259.                     // add notes
  260.                     if (notes!=null)
  261.                         newMessages['UN'] = notes;
  262.  
  263.                     //add deviations
  264.                     if (deviations!=null)
  265.                         newMessages['D'] = deviations;
  266.  
  267.                     //add contests
  268.                     if (contests!=null && contests!=0)
  269.                         newMessages['CA'] = contests;
  270.  
  271.                     //add admin
  272.                     if (admin!=null && admin!=0)
  273.                         newMessages['AM'] = admin;
  274.                     
  275.                     //add critiques
  276.                     if (critiques!=null && critiques!=0)
  277.                         newMessages['WC'] = critiques;
  278.  
  279.  
  280.                     for (f=0;f<_messages.length;f++)
  281.                     {
  282.                         match = ro_cvds_daInstance.REGEXP_SPLIT_MSG.exec(_messages[f]);
  283.                         key = match[2];
  284.                         value = match[1];
  285.                         newMessages[key] = value;
  286.                     }
  287.                     ro_cvds_daInstance.handleMessages(newMessages, html);
  288.                     ro_cvds_daInstance.changeStatus("Messages successfully retrieved");
  289.                 }
  290.                 else
  291.                 {
  292.                     ro_cvds_daInstance.killAnimation();
  293.                     panel.setAttribute("label","No Messages");
  294.                     ro_cvds_daUtils.setPref("lastMessages","",ro_cvds_daUtils.stringPref);
  295.                     ro_cvds_daInstance.messages = new Array();
  296.                     ro_cvds_daInstance.changeStatus("Messages successfully retrieved: no messages");
  297.                 }
  298.  
  299.             }
  300.  
  301.             //user not logged in ... DO NOT FORGET: to check if it's also the case of deviantart in read-only mode
  302.             if (ro_cvds_daInstance.req.status == 403)
  303.             {
  304.                 password = ro_cvds_daUtils.getUserData()?ro_cvds_daUtils.getUserData().password:null;
  305.                 if (ro_cvds_daUtils.getPref("useautologin",ro_cvds_daUtils.boolPref) && ro_cvds_daUtils.getPref("username",ro_cvds_daUtils.stringPref) && password)
  306.                 {
  307.                     ro_cvds_daInstance.login(password);
  308.                 }
  309.                 else
  310.                 {
  311.                     ro_cvds_daInstance.killAnimation();
  312.                     panel.setAttribute("label","Not logged in");
  313.                     ro_cvds_daInstance.changeStatus("You must be logged in on deviantArt or use the auto-login option from deviantAnywhere's advanced settings.",true);
  314.                 }
  315.             }
  316.         }
  317.     },
  318.  
  319.     setTooltip: function(message, title)
  320.     {
  321.         toolTip = document.getElementById("da-Tip");
  322.  
  323.         while (toolTip.hasChildNodes())
  324.             toolTip.removeChild(toolTip.firstChild);
  325.  
  326.         if (title)
  327.         {
  328.             toolTipTitle = document.createElement("description");
  329.             toolTipTitle.setAttribute("value", title);
  330.             toolTipTitle.setAttribute("id", "tipTitle");
  331.             toolTip.appendChild(toolTipTitle);
  332.         }
  333.  
  334.         toolTipEntry = document.createElement("description");
  335.         toolTipEntry.setAttribute("value", message);
  336.         toolTip.appendChild(toolTipEntry);
  337.     },
  338.  
  339.     handleMessages: function(newMessages, html)
  340.     {
  341.         hasNew = false;
  342.         statusBarText = "";
  343.  
  344.         toolTip = document.getElementById("da-Tip");
  345.  
  346.         //clear the tooltip
  347.         if (toolTip)
  348.         while (toolTip.hasChildNodes())
  349.             toolTip.removeChild(toolTip.firstChild);
  350.  
  351.         if (toolTip)
  352.         {
  353.             toolTipEntry = document.createElement("description");
  354.             toolTipEntry.setAttribute("value", "Messages for "+deviantName);
  355.             toolTipEntry.setAttribute("id", "tipTitle");
  356.             toolTip.appendChild(toolTipEntry);
  357.         }
  358.  
  359.  
  360.         //build the status bar message & tooltip
  361.         hasNew = false;
  362.         for (item in newMessages)
  363.         {
  364.             thisIsNew = false;
  365.             if ((this.messages[item]==undefined && newMessages[item]!=0) || (this.messages[item] && this.messages[item]<newMessages[item]))
  366.             {
  367.                 hasNew = true;
  368.                 thisIsNew = true;
  369.             }
  370.             this.messages[item] = newMessages[item];
  371.             if (this.messages[item]!=0)
  372.             {
  373.                 statusBarText += this.messages[item]+item+" ";
  374.  
  375.                 if (toolTip)
  376.                 {
  377.                     toolTipEntry = document.createElement("description");
  378.                     toolTipEntry.setAttribute("value", this.messages[item]+" "+(this.descs[item]?this.descs[item].split("::")[this.messages[item]==1?0:1]:item));
  379.                     toolTip.appendChild(toolTipEntry);
  380.                 }
  381.             }
  382.         }
  383.         if (statusBarText=="")
  384.         {
  385.             statusBarText = "dA";
  386.  
  387.             if (toolTip)
  388.             {
  389.                 toolTipEntry = document.createElement("description");
  390.                 toolTipEntry.setAttribute("value", "None");
  391.                 toolTip.appendChild(toolTipEntry);
  392.             }
  393.         }
  394.         panel.setAttribute("label",statusBarText);
  395.  
  396.         if (hasNew)
  397.         {
  398.             if (ro_cvds_daUtils.getPref("openNotification",ro_cvds_daUtils.boolPref))
  399.                 this.getContents(html);
  400.             if (ro_cvds_daUtils.getPref("playsound",ro_cvds_daUtils.boolPref))
  401.                 this.playSound(ro_cvds_daUtils.getPref("sound"));
  402.             if (ro_cvds_daUtils.getPref("openMsgOnNew",ro_cvds_daUtils.boolPref))
  403.                 setTimeout("ro_cvds_daInstance.openURL(ro_cvds_daInstance.messagesURL,ro_cvds_daUtils.getPref('focusTab',ro_cvds_daUtils.boolPref))",500);
  404.             ro_cvds_daUtils.setPref("lastMessages",ro_cvds_daUtils.array2JSON(newMessages),ro_cvds_daUtils.stringPref);
  405.         }
  406.     },
  407.  
  408.     getContents: function(html)
  409.     {
  410.         this.prev_deviations = new Array();
  411.         this.prev_notes = new Array();
  412.         this.prev_watch = new Array();
  413.         this.prev_comments = new Array();
  414.         this.prev_favs = new Array();
  415.  
  416.         deviations = this.preg_matchall(this.REGEXP_PREV_DEVIATIONS, html)
  417.         for(f=0;f<deviations.length;f++)
  418.         {
  419.             this.prev_deviations[f] = new Array();
  420.  
  421.             this.prev_deviations[f][0] = deviations[f][1]+deviations[f][3];
  422.             this.prev_deviations[f][1] = this.clearURL(deviations[f][2]);
  423.  
  424.             this.prev_deviations[f][2] = deviations[f][5];
  425.             this.prev_deviations[f][3] = this.clearURL(deviations[f][4]);
  426.         }
  427.  
  428.         notes = this.preg_matchall(this.REGEXP_PREV_NOTES, html)
  429.         for(f=0;f<notes.length;f++)
  430.         {
  431.             this.prev_notes[f] = new Array();
  432.  
  433.             this.prev_notes[f][0] = notes[f][1]+notes[f][3];
  434.             this.prev_notes[f][1] = this.clearURL(notes[f][2]);
  435.  
  436.             this.prev_notes[f][2] = notes[f][5];
  437.             this.prev_notes[f][3] = this.clearURL(notes[f][4]);
  438.         }
  439.  
  440.         favs = this.preg_matchall(this.REGEXP_PREV_FAVS, html)
  441.         for(f=0;f<favs.length;f++)
  442.         {
  443.             this.prev_favs[f] = new Array();
  444.  
  445.             this.prev_favs[f][0] = favs[f][1]+favs[f][3];
  446.             this.prev_favs[f][1] = this.clearURL(favs[f][2]);
  447.  
  448.             this.prev_favs[f][2] = favs[f][7];
  449.             this.prev_favs[f][3] = this.clearURL(favs[f][6]);
  450.  
  451.             this.prev_favs[f][4] = favs[f][5];
  452.             this.prev_favs[f][5] = this.clearURL(favs[f][4]);
  453.         }
  454.  
  455.         watch = this.preg_matchall(this.REGEXP_PREV_WATCH, html)
  456.         for(f=0;f<watch.length;f++)
  457.         {
  458.             this.prev_watch[f] = new Array();
  459.  
  460.             this.prev_watch[f][0] = watch[f][1]+watch[f][3];
  461.             this.prev_watch[f][1] = this.clearURL(watch[f][2]);
  462.         }
  463.  
  464.         comments = this.preg_matchall(this.REGEXP_PREV_COMMENTS, html)
  465.         for(f=0;f<comments.length;f++)
  466.         {
  467.             this.prev_comments[f] = new Array();
  468.  
  469.             this.prev_comments[f][0] = comments[f][1]+comments[f][3];
  470.             this.prev_comments[f][1] = this.clearURL(comments[f][2]);
  471.  
  472.             this.prev_comments[f][2] = comments[f][5];
  473.             this.prev_comments[f][3] = this.clearURL(comments[f][4]);
  474.  
  475.             this.prev_comments[f][4] = this.clearURL(comments[f][6]);
  476.         }
  477.  
  478.         critiques = this.preg_matchall(this.REGEXP_PREV_CRITIQUES, html)
  479.         for(f=0;f<critiques.length;f++)
  480.         {
  481.             this.prev_critiques[f] = new Array();
  482.  
  483.             this.prev_critiques[f][0] = critiques[f][1]+critiques[f][3]
  484.             this.prev_critiques[f][1] = this.clearURL(critiques[f][2]);
  485.             
  486.             this.prev_critiques[f][2] = this.clearURL(critiques[f][4]);
  487.             
  488.             this.prev_critiques[f][3] = this.clearURL(critiques[f][5]);
  489.             
  490.             this.prev_critiques[f][4] = critiques[f][6];
  491.             
  492.             this.prev_critiques[f][5] = critiques[f][7]+critiques[f][9]
  493.             this.prev_critiques[f][6] = this.clearURL(critiques[f][8]);
  494.         }
  495.  
  496.         journals = this.preg_matchall(this.REGEXP_PREV_JOURNALS, html)
  497.         for(f=0;f<journals.length;f++)
  498.         {
  499.             this.prev_journals[f] = new Array();
  500.  
  501.             this.prev_journals[f][0] = journals[f][1]+journals[f][3];
  502.             this.prev_journals[f][1] = this.clearURL(journals[f][2]);
  503.  
  504.             this.prev_journals[f][2] = journals[f][5];
  505.             this.prev_journals[f][3] = this.clearURL(journals[f][4]);
  506.         }
  507.  
  508.  
  509.         this.showNotification();
  510.     },
  511.  
  512.     clearURL: function(url)
  513.     {
  514.         return url.replace(/\\/g, "");
  515.     },
  516.  
  517.  
  518.  
  519.     preg_matchall: function(regexp, target)
  520.     {
  521.         result = new Array();
  522.         hellFrezesOver = true;
  523.         do{
  524.             parts = regexp.exec(target)
  525.             if (parts==null)
  526.                 break;
  527.             result[result.length] = parts;
  528.             target = target.replace(regexp,"");
  529.         }while (hellFrezesOver);
  530.         return result;
  531.     },
  532.  
  533.     openURL: function(URL, alsoFocus)
  534.     {
  535.         if (alsoFocus)
  536.             gBrowser.selectedTab = gBrowser.addTab(URL);
  537.         else
  538.             gBrowser.addTab(URL);
  539.     },
  540.  
  541.     openWindow: function(url,name,panel)
  542.     {
  543.         var windowMediator = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator);
  544.         var topWindow = windowMediator.getMostRecentWindow(name);
  545.  
  546.         if (topWindow)
  547.             topWindow.focus();
  548.         else
  549.         {
  550.             topWindow = windowMediator.getMostRecentWindow(null);
  551.             topWindow.openDialog(url, "_blank", "chrome,toolbar,centerscreen", panel);
  552.         }
  553.     },
  554.  
  555.     openConfig: function()
  556.     {
  557.         this.openWindow("chrome://devany/content/settings.xul","devAny:settings",["dA-main"])
  558.     },
  559.  
  560.  
  561.     openAbout: function()
  562.     {
  563.         this.openWindow("chrome://devany/content/about.xul","devAny:about",[])
  564.     },
  565.  
  566.  
  567.     playSound: function(userSound)
  568.     {
  569.       var sample = Components.classes["@mozilla.org/sound;1"].createInstance().QueryInterface(Components.interfaces.nsISound);
  570.       var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
  571.       sample.play(ioService.newURI(userSound, null, null));
  572.     },
  573.  
  574.     checkNow: function()
  575.     {
  576.         clearTimeout(this.timer);
  577.         loginRetry = 0;
  578.         this.retrieveMessages();
  579.     },
  580.  
  581.     login: function(password)
  582.     {
  583.         var dataString = "username="+ro_cvds_daUtils.getPref("username",ro_cvds_daUtils.stringPref)+"&password="+password+"&reusetoken=1";
  584.  
  585.         this.loginReq.open("POST", this.loginURL, true);
  586.         this.loginReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  587.         this.loginReq.onreadystatechange = this.loginEnd;
  588.         this.loginReq.sendAsBinary(dataString);
  589.     },
  590.  
  591.     loginEnd: function()
  592.     {
  593.         if(this.readyState == 4 && this.status == 200)
  594.         {
  595.             if (ro_cvds_daInstance.loginRetry<3)
  596.             {
  597.                 ro_cvds_daInstance.loginRetry++;
  598.                 clearTimeout(ro_cvds_daInstance.timer);
  599.                 ro_cvds_daInstance.retrieveMessages();
  600.             }
  601.             else
  602.             {
  603.                 ro_cvds_daInstance.killAnimation();
  604.                 panel.setAttribute("label","Not logged in");
  605.                 ro_cvds_daInstance.changeStatus("Invalid deviant name/password provided in auto-login",true);
  606.             }
  607.         }
  608.     },
  609.  
  610.     openStatus: function()
  611.     {
  612.         this.openWindow("chrome://devany/content/status.xul","devAny:status",[])
  613.     },
  614.  
  615.     showNotification: function()
  616.     {
  617.         window.open("chrome://devany/content/alert.xul","notifier","chrome,dialog=yes,titlebar=no,popup=yes");
  618.     },
  619.  
  620.     openMessages: function()
  621.     {
  622.         this.openURL(this.messagesURL,true);
  623.     }
  624. }
  625.  
  626. var ro_cvds_daInstance = new deviantAnywhere();
  627.  
  628. function ro_cvds_initDa()
  629. {
  630.     ro_cvds_daInstance.init();
  631. }
  632.  
  633. window.addEventListener("load", ro_cvds_initDa, false);
  634.